﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Entities;

/// <summary>
/// Summary description for BankDAL
/// </summary>
public class BankDAL
{
    public static readonly BankDAL Instance = new BankDAL();
    public BankDAL()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public DataTable ListAccount(String ClientNumber)
    {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = new SqlParameter("@ClientNumber", SqlDbType.VarChar);
        paramList[0].Value = ClientNumber;
        return DatabaseAccess.dbac.executeSelect("ListAccount", paramList);
    }
    public DataTable AccountDetail(String AccountNumber)
    {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = new SqlParameter("@AccountNumber", SqlDbType.VarChar);
        paramList[0].Value = AccountNumber;
        return DatabaseAccess.dbac.executeSelect("AccountDetail", paramList);
    }
    public DataTable AccountTypeName(int AccountTypeID)
    {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = new SqlParameter("@AccountTypeID", SqlDbType.Int);
        paramList[0].Value = AccountTypeID;
        return DatabaseAccess.dbac.executeSelect("AccountTypeName", paramList);
    }
    public bool LastTransaction(String ACN)
    {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = new SqlParameter("@AccountNumber", SqlDbType.VarChar);
        paramList[0].Value = ACN;
        return DatabaseAccess.dbac.executeUpdate("LastTransaction", paramList);
    }
    public bool InsertTransaction(String TransType, String ACN, String Amount, String Description, int Status)
    {
        SqlParameter[] paramList = new SqlParameter[5];
        paramList[0] = new SqlParameter("@TransType", SqlDbType.NVarChar);
        paramList[0].Value = TransType;
        paramList[1] = new SqlParameter("@AccountNumber", SqlDbType.VarChar);
        paramList[1].Value = ACN;
        paramList[2] = new SqlParameter("@Amount", SqlDbType.Money);
        paramList[2].Value = Amount;
        paramList[3] = new SqlParameter("@Description", SqlDbType.NVarChar);
        paramList[3].Value = Description;
        paramList[4] = new SqlParameter("@Status", SqlDbType.Int);
        paramList[4].Value = Status;
        return DatabaseAccess.dbac.executeUpdate("InsertTransactions", paramList);
    }
    public bool Deposit(String ACN, String Balance)
    {
        SqlParameter[] paramList = new SqlParameter[2];
        paramList[0] = new SqlParameter("@AccountNumber", SqlDbType.VarChar);
        paramList[0].Value = ACN;
        paramList[1] = new SqlParameter("@Balance", SqlDbType.Money);
        paramList[1].Value = Balance;
        return DatabaseAccess.dbac.executeUpdate("Deposit", paramList);
    }
    public bool WithDraw(String ACN, String Balance)
    {
        SqlParameter[] paramList = new SqlParameter[2];
        paramList[0] = new SqlParameter("@AccountNumber", SqlDbType.VarChar);
        paramList[0].Value = ACN;
        paramList[1] = new SqlParameter("@Balance", SqlDbType.Money);
        paramList[1].Value = Balance;
        return DatabaseAccess.dbac.executeUpdate("WithDraw", paramList);
    }
    public DataTable ViewTransactionByDate(DateTime begindate, DateTime enddate, String ACN)
    {
        SqlParameter[] paramList = new SqlParameter[3];
        paramList[0] = new SqlParameter("@BeginDate", SqlDbType.DateTime);
        paramList[0].Value = begindate;
        paramList[1] = new SqlParameter("@EndDate", SqlDbType.DateTime);
        paramList[1].Value = enddate;
        paramList[2] = new SqlParameter("@AccountNumber", SqlDbType.VarChar);
        paramList[2].Value = ACN;
        return DatabaseAccess.dbac.executeSelect("ViewTransactionByDate", paramList);
    }
    //dang nhap
    public DataTable LoginBank(String ClientNumber, String Password)
    {
        SqlParameter[] paramList = new SqlParameter[2];
        paramList[0] = new SqlParameter("@ClientNumber", SqlDbType.VarChar);
        paramList[0].Value = ClientNumber;
        paramList[1] = new SqlParameter("@Password", SqlDbType.VarChar);
        paramList[1].Value = Password;
        return DatabaseAccess.dbac.executeSelect("LoginBankClient", paramList);
    }
    //luu mau chuyen khoan
    public bool SaveTransaction(String SampleTName,String ACN,String Beneficiary,String ToACN,String Bank,String City,String Branch,float TransactionLimit,String Money,String TransactionContent,int Category)
    {
        SqlParameter[] paramList = new SqlParameter[11];
        paramList[0] = new SqlParameter("@SampleTName",SqlDbType.NVarChar);
        paramList[0].Value = SampleTName;
        paramList[1] = new SqlParameter("@ACN",SqlDbType.VarChar);
        paramList[1].Value = ACN;
        paramList[2] = new SqlParameter("Beneficiary",SqlDbType.NVarChar);
        paramList[2].Value = Beneficiary;
        paramList[3] = new SqlParameter("@ToACN",SqlDbType.VarChar);
        paramList[3].Value = ToACN;
        paramList[4] = new SqlParameter("@Bank",SqlDbType.NVarChar);
        paramList[4].Value = Bank;
        paramList[5] = new SqlParameter("@City",SqlDbType.NVarChar);
        paramList[5].Value = City;
        paramList[6] = new SqlParameter("@Branch",SqlDbType.NVarChar);
        paramList[6].Value = Branch;
        paramList[7] = new SqlParameter("@TransactionLimit",SqlDbType.Float);
        paramList[7].Value = TransactionLimit;
        paramList[8] = new SqlParameter("@Money",SqlDbType.Money);
        paramList[8].Value = Money;
        paramList[9] = new SqlParameter("@TransactionContent",SqlDbType.NVarChar);
        paramList[9].Value = TransactionLimit;
        paramList[10] = new SqlParameter("@Category",SqlDbType.Int);
        paramList[10].Value = Category;
       return DatabaseAccess.dbac.executeUpdate("SaveTransaction", paramList);
    }

}
